from typing import Optional
from pydantic import BaseModel, ConfigDict, model_validator

class Double_Room_Public(BaseModel):
    model_config = ConfigDict(from_attributes=True, populate_by_name=True)

    room_id :Optional[str] = None
    created_at :Optional[str] = None
    is_active :Optional[bool] = True
    one:Optional[int] = None
    another:Optional[int] = None
    type :Optional[str] = 'double'

    @model_validator(mode='before')
    def filter_fields(cls, data):
        allowed_fields = {
            "room_id","created_at","is_active","another","one",'type'
        }
        if isinstance(data, dict):
            # 如果输入是字典，直接过滤
            return {k: v for k, v in data.items() if k in allowed_fields}
        else:
            # 如果输入是SQLAlchemy模型实例
            return {k: getattr(data, k) for k in allowed_fields if hasattr(data, k)}
